package cn.schoolwow.util.domain.query.jsonobject;

import cn.schoolwow.quickflow.QuickFlowBuilder;
import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.util.module.query.jsonobject.domain.JSONObjectQueryOption;
import cn.schoolwow.util.module.query.jsonobject.service.GetJSONObjectFieldsValueFlow;

import java.util.Arrays;
import java.util.Collection;

public class QueryJSONObjectResponse {
    private JSONObjectQueryOption jsonObjectQueryOption;

    public QueryJSONObjectResponse(JSONObjectQueryOption jsonObjectQueryOption) {
        this.jsonObjectQueryOption = jsonObjectQueryOption;
    }

    /**获取指定字段值*/
    public Object getFieldValue(String fieldName){
        Object fieldValue = jsonObjectQueryOption.object.get(fieldName);
        return fieldValue;
    }

    /**获取指定多个字段值*/
    public Object getMultipleFieldValue(String... fieldNames){
        return getMultipleFieldValue(Arrays.asList(fieldNames));
    }

    /**获取指定多个字段值*/
    public Object getMultipleFieldValue(Collection<String> fieldNames){
        FlowContext flowContext = QuickFlowBuilder.quickFlow().startFlow(new GetJSONObjectFieldsValueFlow())
                .putCurrentCompositeFlowData("jsonObjectQueryOption", jsonObjectQueryOption)
                .putCurrentCompositeFlowData("fieldNames", fieldNames)
                .execute();
        Object fieldValue = flowContext.getData("fieldValue");
        return fieldValue;
    }

}
